﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace SPVisualDev.VSAddin.Dialogs.PropertySheets
{
    public class ResourcePropertyDescriptor : PropertyDescriptor
    {
        private bool m_is_readonly;

        public ResourcePropertyDescriptor(string Name, Attribute[] attributes)
            : base(Name, attributes)
        {
        }

        public void SetReadOnlyFlag(bool IsReadOnly)
        {
            m_is_readonly = IsReadOnly;
        }

        public override bool CanResetValue(object component)
        {
            return false;
        }

        public override Type ComponentType
        {
            get { throw new NotImplementedException(); }
        }

        public override bool IsReadOnly
        {
            get { return m_is_readonly; }
        }

        public override Type PropertyType
        {
            get { return typeof(string); }
        }

        public override void ResetValue(object component)
        {

        }

        public override object GetValue(object component)
        {
            ResourceStringContainer container = component as ResourceStringContainer;

            string s = this.Name;
            if (s == "(Default)")
                s = null;
            else
                s = this.Name.Split(' ')[0];

            return container.GetValue(s);
        }

        public override void SetValue(object component, object value)
        {
            ResourceStringContainer container = component as ResourceStringContainer;

            string s = this.Name;
            if (s == "(Default)")
                s = null;
            else
                s = this.Name.Split(' ')[0];

            container.SetValue(s, value as string);
        }

        public override bool ShouldSerializeValue(object component)
        {
            return false;
        }
    }

}
